package com.yuanchu.store.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-23 17:29
 */
@Configuration
public class DearMessageConfig {

    // 声明普通的 paynotify_marketing_queue队列，并且为其指定死信交换机：dl.direct
    //支付通知用户队列
    public static final String PAYNOTIFY_STORE_QUEUE = "paynotify_store_queue";

    // 声明存储死信的队列
    public static final String DL_STORE_QUEUE = "dl_store_queue";

    public static final String DL_STORE_DIRECT = "dl_store_direct";
    public static final String DL_STORE_KEY = "store";
    @Bean
    public Queue simpleQueue2(){
        return QueueBuilder.durable(PAYNOTIFY_STORE_QUEUE) // 指定队列名称，并持久化
                .deadLetterExchange(DL_STORE_DIRECT) // 指定死信交换机
                .build();
    }
    // 声明死信交换机 dl.direct
    @Bean
    public DirectExchange dlExchange(){
        return new DirectExchange(DL_STORE_DIRECT, true, false);
    }
    // 声明存储死信的队列 dl.queue
    @Bean
    public Queue dlQueue(){
        return new Queue(DL_STORE_QUEUE, true);
    }
    // 将死信队列 与 死信交换机绑定
    @Bean
    public Binding dlBinding(){
        return BindingBuilder.bind(dlQueue()).to(dlExchange()).with(DL_STORE_KEY);
    }
}
